.\"
.\" FreeBSD pkg - a next generation package for the installation and maintenance
.\" of non-core utilities.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\"
.\"     @(#)pkg.8
.\"
.Dd September 26, 2015
.Dt PKG-CREATE 8
.Os
.\" ---------------------------------------------------------------------------
.Sh NAME
.Nm "pkg create"
.Nd a utility for creating software package distributions
.\" ---------------------------------------------------------------------------
.Sh SYNOPSIS
.Nm
.Op Fl nqv
.Op Fl f Ar format
.Op Fl o Ar outdir
.Op Fl p Ar plist
.Op Fl r Ar rootdir
.Fl m Ar metadatadir
.Nm
.Op Fl nqv
.Op Fl f Ar format
.Op Fl o Ar outdir
.Op Fl r Ar rootdir
.Fl M Ar manifest
.Nm
.Op Fl gnqvx
.Op Fl f Ar format
.Op Fl o Ar outdir
.Op Fl r Ar rootdir
.Ar pkg-name ...
.Nm
.Op Fl nqv
.Op Fl f Ar format
.Op Fl o Ar outdir
.Op Fl r Ar rootdir
.Fl a
.\" ---------------------------------------------------------------------------
.Pp
.Nm
.Op Cm --no-clobber
.Op Cm --quiet
.Op Cm --verbose
.Op Cm --format Ar format
.Op Cm --out-dir Ar outdir
.Op Cm --plist Ar plist
.Op Cm --root-dir Ar rootdir
.Cm --metadata Ar metadatadir
.Nm
.Op Cm --no-clobber
.Op Cm --quiet
.Op Cm --verbose
.Op Cm --format Ar format
.Op Cm --out-dir Ar outdir
.Op Cm --root-dir Ar rootdir
.Cm --manifest Ar manifest
.Nm
.Op Cm --{glob,no-clobber,regex}
.Op Cm --quiet
.Op Cm --verbose
.Op Cm --format Ar format
.Op Cm --out-dir Ar outdir
.Op Cm --root-dir Ar rootdir
.Ar pkg-name ...
.Nm
.Op Cm --no-clobber
.Op Cm --quiet
.Op Cm --verbose
.Op Cm --format Ar format
.Op Cm --out-dir Ar outdir
.Op Cm --root-dir Ar rootdir
.Cm --all
.\" ---------------------------------------------------------------------------
.Sh DESCRIPTION
.Nm
is used to create packages from binaries or other files installed on
your computer.
Package tarballs can be created from the files of a previously installed
package using metadata from the local package database.
Any number of packages may be created in one invocation of this style.
.Pp
Alternatively, a single package can be created from an arbitrary
selection of files on your system, but this requires a
.Ar metadatadir
and optionally
.Ar plist
to be supplied.
The package name will be derived from the
.Pa +MANIFEST
file which must be contained within the
.Ar metadatadir ,
or passed as the argument to
.Fl M .
.Pp
Packages thus created can be distributed and subsequently installed on
other machines using the
.Cm pkg add
command.
.\" ---------------------------------------------------------------------------
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width ".Fl m Ar metadatadir"
.It Fl a , Cm --all
Create package tarballs from all packages installed on your system.
This option is incompatible with the
.Fl g , x
or
.Fl m Ar metadatadir
options.
.It Fl g , Cm --glob
Interpret
.Ar pkg-name
as a shell glob pattern and create package only for installed binaries whose
name match this pattern.
This option is incompatible with the
.Fl a , x
or
.Fl m Ar metadatadir
options.
.It Fl x , Cm --regex
Like
.Fl g ,
but interpret
.Ar pkg-name
as a regular expression using the "modern" or "extended" syntax described in
.Xr re_format 7 .
This option is incompatible with the
.Fl a, g
or
.Fl m Ar metadatadir
options.
.It Fl f Ar format , Cm --format Ar format
Set
.Ar format
as the package output format.
It can be one of
.Ar tzst, txz , tbz , tgz
or
.Ar tar
which are currently the only supported formats.
If an invalid or no format is specified
.Ar txz
is assumed.
.It Fl m Ar metadatadir , Cm --metadata Ar metadatadir
Specify the directory containing the package manifest,
.Pa +MANIFEST
and optionally three other files; one containing a message to be
displayed on package installation,
.Pa +DISPLAY .
Another containing the description for the package,
.Pa +DESC .
If specified, only a single package will be created.
.Pa +DISPLAY
and
.Pa +DESC
are not required; the
.Pa +MANIFEST
file can contain all the required information needed to build a
package.
This option is incompatible with the
.Fl M, a, g
or
.Fl x
options.
.It Fl M Ar manifest , Cm --manifest Ar manifest
Read all of the package metadata from the
.Ar manifest
file.
This is exactly the same format as
.Pa +MANIFEST
mentioned above, but any file name can be used, and no
other file will be used to read package metadata from.
If specified, only a single package will be created.
This option is incompatible with the
.Fl m, a, g
or
.Fl x
options.
.It Fl n , Cm --no-clobber
Do not overwrite already existing packages.
.It Fl o Ar outdir , Cm --out-dir Ar outdir
Set
.Ar outdir
as the output directory.
If this option is not given, all created packages will
be saved in the current directory.
.It Fl p Ar plist , Cm --plist Ar plist
Specify some package metadata using the legacy plist format from
.Xr pkg_add 1 ,
commonly found in
.Pa pkg-plist
files in the ports tree.
Metadata from the
.Ar plist
file, if specified, will take precedence over any equivalents from
the
.Ar metadatadir .
Only has any effect when used with
.Ar metadatadir .
See
.Sx "PLIST FORMAT"
for details.
.It Fl q , Cm --quiet
Force quiet output.
This is the default, unless
.Cm PKG_CREATE_VERBOSE
is set to
.Ar yes
in
.Pa pkg.conf .
.It Fl v , Cm --verbose
Force verbose output, the opposite of
.Cm --quiet .
.It Fl r Ar rootdir , Cm --root-dir Ar rootdir
.Ar rootdir
specifies the top-level directory to be treated as the root of the
filesystem hierarchy containing the package files.
File paths in generated packages will be relative to
.Ar rootdir .
This allows a package to be generated from content offset from its
intended final location, which allows a package building without
disturbing similar content already on the system.
If unspecified, the default is effectively
.Pa / ,
the actual root directory.
.El
.\" ---------------------------------------------------------------------------
.Sh MANIFEST FILE DETAILS
.Bl -tag -width ".Cm www"
.It Cm name Ar pkg-name
This entry sets the package's name to
.Ar pkg-name . \" TODO: Find out why there is a space after the ``.''
Among other things, this name is used - with the version and the origin of the
concerned package - to identify a dependency.
.It Cm version Ar pkg-version
This entry sets the package's version to
.Ar pkg-version .
.It Cm origin Ar pkg-origin
This entry sets the package's origin to
.Ar pkg-origin .
This is a string of the form
.Pa category/port-dir
which designates the port this package was built from.
.It Cm comment Ar comment-string
.Ar comment-string
is a one-line description of this package.
It is the equivalent of the
.Dv COMMENT
variable for a port, not a way to put comments in a
.Pa +MANIFEST
file.
.It Cm desc Ar description
.Ar description
is a longer description of the package.
It is the equivalent of the
.Pa pkg-descr
file for a port.
It may be one to a few paragraphs.
For example:
.Bd -literal -offset indent
desc = <<EOD
   This is a longer description of the package.
   It can span multiple lines.

   It can also span multiple paragraphs.
EOD
.Ed
.It Cm arch Ar cpu-type
The architecture of the machine the package was built on.
.Ar cpu-type
takes values like x86, amd64...
.It Cm www Ar url
The software's official website.
.It Cm maintainer Ar mail-address
The maintainer's mail address.
.It Cm prefix Ar path-prefix
The path where the files contained in this package are installed
.Pq usually Pa /usr/local .
.It Cm flatsize Ar size
The size that the files contained in this package will occupy on your system
once uncompressed.
This value does not take into account files stored in the
package database.
.It Cm deps Ar dep-name dep-origin dep-version
Associative array of package dependencies, keyed on
.Ar dep-name
and with values
.Cm version Ar dep-version
and
.Cm origin Ar dep-origin .
For example:
.Bd -literal -offset indent
"deps" : {
   "pstree" : {
      "version" : "2.36",
      "origin" : "sysutils/pstree"
   },
   "cdiff" : {
      "version" : "0.9.6.20140711,1",
      "origin" : "textproc/cdiff"
   },
},
.Ed
.It Cm conflict Ar pkg-glob
Flag this package as incompatible with the one designated by
.Ar pkg-glob .
Conflicting packages cannot be installed on the same system as they may contain
references to the sames files.
.It Cm option Ar option-name option-value
Set the option
.Ar option-name
to the value
.Ar option-value .
.It Cm file Ar sha256-hash path
.Cm file
entries list files included in the package.
If the file is a regular one, such
an entry contains its sha256 digest along with its path.
If a packaged file is
a link, you must use this entry's other form, as described below.
.It Cm file Ar - path
Same as above but for file links.
The sha256 hash is replaced with a
.Ar -
(dash).
.It Cm dir Ar path
Mimics the
.Cm file
entry but for directories.
.El
.Sh PLIST FORMAT
The following describes the plist format:
.Pp
The plist is a sequential list of lines which can have keywords prepended.
A keyword starts with an
.Sq @ .
Lines not starting with a keyword are considered as paths to a file.
If started with a
.Sq /
then it is considered an absolute path.
Otherwise the file is considered as relative to
.Ev PREFIX .
.Pp
Keyword lines are formed as follows:
.Ar @keyword
.Ar line
.Pp
Available keywords are the following:
.Pp
.Bl -tag -width indent -compact
.It Cm @cwd Op Ar directory
Set the internal directory pointer to point to
.Ar directory .
All subsequent filenames will be assumed relative to this directory.
.It Cm @preexec Ar Command
Execute
.Ar command
as part of the pre-install scripts.
.It Cm @preunexec Ar command
Execute
.Ar command
as part of the pre-deinstall scripts.
.It Cm @postexec Ar command
Execute
.Ar command
as part of the post-install scripts.
.It Cm @postunexec Ar command
Execute
.Ar command
as part of the post-deinstall scripts.
.It Cm @exec Ar command Pq deprecated
Execute
.Ar command
as part of the unpacking process.
If
.Ar command
contains any of the following sequences somewhere in it, they will
be expanded inline.
For the following examples, assume that
.Cm @cwd
is set to
.Pa /usr/local
and the last extracted file was
.Pa bin/emacs .
.Bl -tag -width indent -compact
.It Cm "%F"
Expands to the last filename extracted (as specified), in the example case
.Pa bin/emacs
.It Cm "\&%D"
Expand to the current directory prefix, as set with
.Cm @cwd ,
in the example case
.Pa /usr/local .
.It Cm "\&%B"
Expand to the
.Dq basename
of the fully qualified filename, that is the current directory prefix,
plus the last filespec, minus the trailing filename.
In the example case, that would be
.Pa /usr/local/bin .
.It Cm "%f"
Expand to the filename part of the fully qualified name, or
the converse of
.Cm \&%B ,
being in the example case,
.Pa emacs .
.El
.It Cm @unexec Ar command Pq deprecated
Execute
.Ar command
as part of the deinstallation process.
Expansion of special
.Cm %
sequences is the same as for
.Cm @exec .
This command is not executed during the package add, as
.Cm @exec
is, but rather when the package is deleted.
This is useful for deleting links and other ancillary files that were
created as a result of adding the package, but not directly known to
the package's table of contents (and hence not automatically
removable).
.It Cm @mode Ar mode
Set default permission for all subsequently extracted files to
.Ar mode .
Format is the same as that used by the
.Cm chmod
command.
Use without an arg to set back to default (mode of the file while being packed)
permissions.
.It Cm @owner Ar user
Set default ownership for all subsequent files to
.Ar user .
Use without an arg to set back to default (root)
ownership.
.It Cm @group Ar group
Set default group ownership for all subsequent files to
.Ar group .
Use without an arg to set back to default (wheel)
group ownership.
.It Cm @comment Ar string
The line will be ignored when packing.
.It Cm @dir Ar name
Declare directory
.Pa name
to be deleted at deinstall time.
By default, most directories created by a package installation are
deleted automatically when the package is deinstalled, so this directive is
only needed for empty directories or directories outside of
.Ev PREFIX .
These directives should appear at the end of the package list.
If the directory is not empty a warning will be printed, and the
directory will not be removed.
(Subdirectories should be listed before parent directories.)
.El
.\" ---------------------------------------------------------------------------
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm .
See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
.It Ev PKG_DBDIR
.It Ev PLIST_KEYWORDS_DIR
.It Ev PORTSDIR
.El
.\" ---------------------------------------------------------------------------
.Sh FILES
See
.Xr pkg.conf 5 .
.\" ---------------------------------------------------------------------------
.Sh EXAMPLES
Create package files for installed packages:
.Dl % pkg create -a -o /usr/ports/packages/All
.Pp
Create package file for pkg:
.Dl % pkg create -o /usr/ports/packages/All pkg
.\" ---------------------------------------------------------------------------
.Sh SEE ALSO
.Xr pkg_printf 3 ,
.Xr pkg_repos 3 ,
.Xr pkg-repository 5 ,
.Xr pkg.conf 5 ,
.Xr pkg 8 ,
.Xr pkg-add 8 ,
.Xr pkg-alias 8 ,
.Xr pkg-annotate 8 ,
.Xr pkg-audit 8 ,
.Xr pkg-autoremove 8 ,
.Xr pkg-backup 8 ,
.Xr pkg-check 8 ,
.Xr pkg-clean 8 ,
.Xr pkg-config 8 ,
.Xr pkg-delete 8 ,
.Xr pkg-fetch 8 ,
.Xr pkg-info 8 ,
.Xr pkg-install 8 ,
.Xr pkg-lock 8 ,
.Xr pkg-query 8 ,
.Xr pkg-register 8 ,
.Xr pkg-repo 8 ,
.Xr pkg-rquery 8 ,
.Xr pkg-search 8 ,
.Xr pkg-set 8 ,
.Xr pkg-shell 8 ,
.Xr pkg-shlib 8 ,
.Xr pkg-ssh 8 ,
.Xr pkg-stats 8 ,
.Xr pkg-update 8 ,
.Xr pkg-updating 8 ,
.Xr pkg-upgrade 8 ,
.Xr pkg-version 8 ,
.Xr pkg-which 8
